package com.lrd.snapshotorder.controller;

import com.lrd.snapshotorder.protocol.ResultData;
import com.lrd.snapshotorder.protocol.dto.address.RecipientAddressListDto;
import com.lrd.snapshotorder.protocol.dto.address.RecipientAddressQueryDto;
import com.lrd.snapshotorder.protocol.dto.address.RecipientAddressSaveDto;
import com.lrd.snapshotorder.protocol.dto.address.SenderAddressListDto;
import com.lrd.snapshotorder.protocol.dto.address.SenderAddressQueryDto;
import com.lrd.snapshotorder.service.RecipientAddressService;
import com.lrd.snapshotorder.service.SenderAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 收货人管理
 */
@RestController
@RequestMapping("/api/v1/address")
public class AddressController {

    @Autowired
    private RecipientAddressService recipientAddressService;
    @Autowired
    private SenderAddressService senderAddressService;

    /**
     * 收获人地址列表
     *
     * @return
     */
    @PostMapping("/queryRecipientAddressList")
    public ResultData<List<RecipientAddressListDto>> queryRecipientAddressList(@RequestBody RecipientAddressQueryDto dto) {

        return recipientAddressService.queryRecipientAddressList(dto);
    }


    /**
     * 保存/编辑收货人地址
     *
     * @return
     */
    @PostMapping("/saveRecipientAddress")
    public ResultData<Boolean> saveRecipientAddress(@RequestBody RecipientAddressSaveDto dto) {

        return recipientAddressService.saveRecipientAddress(dto);
    }


    /**
     * 编辑收货人地址状态
     *
     * @return
     */
    @GetMapping("/setRecipientAddressStatus")
    public ResultData<Boolean> setRecipientAddressStatus(@RequestParam("id") Integer id) {

        return recipientAddressService.setRecipientAddressStatus(id);
    }


    //-----------------发货人地址-------------------

    @GetMapping("/querySenderAddressList")
    public ResultData<List<SenderAddressListDto>> querySenderAddressList(@RequestBody SenderAddressQueryDto dto) {

        return senderAddressService.querySenderAddressList(dto);
    }
}
